var _timer = 30000;
var _split = 1;
var _id = 0;
var _top05 = new Array(5); // e 05 W
var _top10 = new Array(10); // e 10 W
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];

var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;

var btn0_choice = 11;
var btn1_choice = 0.05;
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function chsbtn(t)
{
	if (t > 10) {
		document.all.btn011.className = "btnchoice";
		document.all.btn012.className = "btnchoice";
		document.all.btn013.className = "btnchoice";
		document.all.btn014.className = "btnchoice";
		document.all.btn015.className = "btnchoice";
		document.all.btn016.className = "btnchoice";
		document.all.btn017.className = "btnchoice";
		document.all.btn018.className = "btnchoice";
		document.all.btn019.className = "btnchoice";
		document.all.btn020.className = "btnchoice";
		document.all.btn021.className = "btnchoice";
		document.all.btn022.className = "btnchoice";
		document.all.btn023.className = "btnchoice";
		document.all.btn024.className = "btnchoice";
		document.all.btn025.className = "btnchoice";
		document.all.btn026.className = "btnchoice";
		document.all.btn027.className = "btnchoice";
		document.all.btn028.className = "btnchoice";
		document.all.btn029.className = "btnchoice";
		document.all.btn030.className = "btnchoice";
		document.all.btn031.className = "btnchoice";
		document.all.btn032.className = "btnchoice";
		document.all.btn033.className = "btnchoice";
		document.all.btn034.className = "btnchoice";
		document.all.btn035.className = "btnchoice";
		document.all.btn036.className = "btnchoice";
		document.all.btn037.className = "btnchoice";
		document.all.btn038.className = "btnchoice";
		event.srcElement.className = "btnchoiced";
		btn0_choice = t;
	} else {
		document.all.btn02.className = "btnchoice";
		document.all.btn01.className = "btnchoice";
		document.all.btn005.className = "btnchoice";
		document.all.btn004.className = "btnchoice";
		document.all.btn003.className = "btnchoice";
		document.all.btn002.className = "btnchoice";
		document.all.btn001.className = "btnchoice";
		document.all.btn0005.className = "btnchoice";
		document.all.btn0001.className = "btnchoice";
		event.srcElement.className = "btnchoiced";
		btn1_choice = t;
	}
}

function btnratediff(t)
{
	// window.status = "Cange Rate....";
	if (timer_id) clearTimeout(timer_id);
	var uu = "op.php?op=admin&fp=ratediff&id="+_id+"&bettype=B&number="+btn0_choice+"&rate="+(btn1_choice*t)+"&pagename=0&method=1";
	if (btn0_choice==21) {
		uu+="&top10=";
		for (var i=0; i<10; i++) {
			uu+=_top10[i];
			if (i<9) { uu+=","; }
		}
	} else if (btn0_choice==24) {
		uu+="&top05=";
		for (var i=0; i<5; i++) {
			uu+=_top05[i];
			if (i<4) { uu+=","; }
		}
	}
	//window.open(uu);//debug
	//return false;//debug
	XH1.open("POST", uu, false); 
    try{XH1.send("");}catch(E){}
	window.status = "";
    timer();
}

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=now2&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i, j;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate0(a[0]);
	show_rate1(a[1]);
	show_rate2(a[2]);
	j = 3;
	for (i=1; i<7; i++) {
		show_rate15(2, i, a[j++]);
		show_rate15(4, i, a[j++]);
		show_rate17(7 ,i, a[j++]);
		show_rate23(9 ,i, a[j++]);
	}
	show_titleAmu(a[j++]);
	window.status = "";
	
	timer_id = setTimeout("timer()", _timer);
}

function show_rate23(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = 23;
		ii = i+7;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
		}
		document.all["chg_"+k].innerHTML = "<input type=button onclick=\"ratediff(bt,'"+nms+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(bt,'"+nms+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all["total23_"+j+"_"+t].innerHTML=Math.floor(amount0);
}

function show_rate17(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<4; i++) {
		bt = 17;
		ii = i+4;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
		}
		document.all["chg_"+k].innerHTML = "<input type=button onclick=\"ratediff(bt,'"+nms+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(bt,'"+nms+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all["total17_"+j+"_"+t].innerHTML=Math.floor(amount0);
}

function show_rate15(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = (t==2 ? 15 : 16);
		ii = (bt==16 ? i+2 : i);
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
		}
		document.all["chg_"+k].innerHTML = "<input type=button onclick=\"ratediff(bt,'"+nms+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(bt,'"+nms+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all["total15_"+j+"_"+t].innerHTML=Math.floor(amount0);
}

function show_rate2(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["rate2_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount2_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=6&numbers="+i+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount2_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg2_"+i].innerHTML = "<input type=button onclick=\"ratediff(6,'"+i+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(6,'"+i+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win2_"+i].innerHTML = win1;
		document.all["win2_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.amount2.innerHTML=Math.floor(amount0);
}

function show_rate1(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["rate1_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount1_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=5&numbers="+i+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount1_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg1_"+i].innerHTML = "<input type=button onclick=\"ratediff(5,'"+i+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff(5,'"+i+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[3]);
		document.all["win1_"+i].innerHTML = win1;
		document.all["win1_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.amount1.innerHTML=Math.floor(amount0);
}


function show_rate0(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var a1 = a0[0].split("@");
	var uamount = a1[0]-0;
	var win = (a1[1]-0) / 6;
	var i = 0;
	var j = 0;
	for (i=1; i<50; i++) {
		a00 = a0[i].split("@");
		num = a00[0];
		if (j<10) {
			_top10[j] = num;
			if (j<5) {
				_top05[j] = num;
			}
			j++;
		}
		num2 = (num < 10 ? "0"+num : num);
		rate = a00[1];
		count = a00[2]-0;
		amount = a00[3]-0;
		document.all["num0_"+i].innerHTML = num2;
		document.all["num0_"+i].className = "td1"+colors[g_numcolor[num]];
		document.all["rate0_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount0_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=77&numbers="+num2+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount0_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg0_"+i].innerHTML = "<input type=button onclick=\"ratediff4('"+num2+"',-1)\" value=- class=btnmin>&nbsp;<input type=button onclick=\"ratediff4('"+num2+"',1)\" value=+ class=btnplus>";
		win1 = Math.floor(win - a00[4]);
		document.all["win0_"+i].innerHTML = win1;
		document.all["win0_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.online_sum.innerHTML = (uamount);
	document.all.amount0.innerHTML=Math.floor(amount0);
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}

function gen_rate0()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<5; i++)
		ret += _tb0head;
	ret += "</tr>";
	
	for (j=1; j<=10; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=0; i<5; i++) {
			k = i*10 + j;
			if (k > 49) {
				ret += "<td colspan=5>合计：<b id=amount0></b></td>";
			} else {
				ret += "<td id=num0_"+k+"></td><td nowrap id=amount0_"+k+"></td><td nowrap id=win0_"+k+"></td><td id=rate0_"+k+" class=rate></td><td align=center id=chg0_"+k+"></td>";
			}
		}
	}
	ret += "</table>";
	document.all.div0.innerHTML = ret;
}

function gen_rate1()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb1head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name1[1]+"</td><td nowrap id=amount1_1></td><td nowrap id=win1_1></td><td id=rate1_1 class=rate></td><td align=center id=chg1_1></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name1[2]+"</td><td nowrap id=amount1_2></td><td nowrap id=win1_2></td><td id=rate1_2 class=rate></td><td align=center id=chg1_2></td></tr>";
	ret += "<tr class=td6 align=right><td class=td0>"+_total+"</td><td id=amount1></td><td></td><td></td><td></td></tr>";
	ret += "</table>";
	document.all.div1.innerHTML = ret;
}

function gen_rate2()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb1head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name2[1]+"</td><td nowrap id=amount2_1></td><td nowrap id=win2_1></td><td id=rate2_1 class=rate></td><td align=center id=chg2_1></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name2[2]+"</td><td nowrap id=amount2_2></td><td nowrap id=win2_2></td><td id=rate2_2 class=rate></td><td align=center id=chg2_2></td></tr>";
	ret += "<tr class=td6 align=right><td class=td0>"+_total+"</td><td id=amount2></td><td></td><td></td><td></td></tr>";
	ret += "</table>";
	document.all.div2.innerHTML = ret;
}

function gen_rate15()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[1]+"</td><td colspan=4>"+_name3[2]+"</td><td rowspan=2>"+_total+"</td>"
		+"<td colspan=4>"+_name3[3]+"</td><td colspan=4>"+_name3[4]+"</td><td rowspan=2>"+_total+"</td></tr><tr class=td1>";
	
	for (i=0; i<4; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap>"+_name4+_name5[j]+"</td>";
		for (i=1; i<5; i++) {
			k = (i < 3 ? 15 : 16)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
			if (i==2 || i==4) {
				ret += "<td class=td6 id=total15_"+j+"_"+i+"></td>";
			}
		}
	}
	ret += "</table>";
	document.all.div15.innerHTML = ret;
}

function gen_rate17()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[5]+"</td><td colspan=4>"+_name3[6]+"</td>"
		+"<td colspan=4>"+_name3[7]+"</td><td rowspan=2>"+_total+"</td>"
		+"<td colspan=4>"+_name3[8]+"</td><td colspan=4>"+_name3[9]+"</td><td rowspan=2>"+_total+"</td></tr><tr class=td1>";
	
	for (i=0; i<5; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap>"+_name4+_name5[j]+"</td>";
		for (i=5; i<10; i++) {
			k = (i<8 ? 17 : 23)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
			if (i==7 || i==9) {
				ret += "<td class=td6 id=total"+k+"></td>";
			}
		}
	}
	ret += "</table>";
	document.all.div17.innerHTML = ret;
}

function ratediff(btype, num, rate)
{
	//window.status = "Cange Rate....";
	if (timer_id) clearTimeout(timer_id);
    XH1.open("POST", "op.php?op=admin&fp=ratediff&id="+_id+"&bettype="+btype+"&number="+num+"&rate="+rate+"&pagename=0&method=0",false); 
    try{XH1.send("");}catch(E){}
    window.status = "";
    timer();
}

function ratediff4(num, t)
{
	//window.status = "Cange Rate....";
	if (timer_id) clearTimeout(timer_id);
    XH1.open("POST", "op.php?op=admin&fp=ratediff&id="+_id+"&bettype=4&number="+num+"&rate="+(btn1_choice*t)+"&pagename=0&method=0",false); 
    try{XH1.send("");}catch(E){}
    window.status = "";
    timer();
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate0();
	gen_rate1();
	gen_rate2();
	gen_rate15();
	gen_rate17();
	timer();
}

window.onload = winonload;